﻿namespace ChinaUnicom.Views.Traffics
{
    using ChinaUnicom.TrafficControl;
    using Microsoft.Phone.Controls;
    using System;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Navigation;

    public class DetailsModel : INotifyPropertyChanged
    {
        public DetailsModel(long cellular, long others)
        {
            this.Cellular = cellular;
            this.Others = others;
        }

        long cellular;
        public long Cellular
        {
            get { return cellular; }
            set
            {
                if (value != cellular)
                {
                    cellular = value;
                    NotifyPropertyChanged("Cellular");
                }
            }
        }

        long others;
        public long Others
        {
            get { return others; }
            set
            {
                if (value != others)
                {
                    others = value;
                    NotifyPropertyChanged("Others");
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }

    public partial class DetailsPage : PhoneApplicationPage
    {
        public DetailsPage()
        {
            InitializeComponent();

            Loaded += OnPageLoaded;
        }

        void OnPageLoaded(object sender, RoutedEventArgs e)
        {
            DataContext = new DetailsModel(Traffic.Current.CellularDataLength, Traffic.Current.OthersDataLength);
        }

        private void OnBackClick(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }
    }
}